<%@page import="java.sql.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="javax.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
String DB_URL = "jdbc:mysql://localhost:3306/userinfo";
// 数据库的用户名与密码，需要根据自己的设置
 String USER = "root";
 String PASS = "199945";
 Connection conn = null;
 Statement stmt = null;
 try{
     // 注册 JDBC 驱动
     Class.forName(JDBC_DRIVER);
     // 打开链接
     System.out.println("连接数据库...");
     conn = DriverManager.getConnection(DB_URL,USER,PASS);
     // 执行查询
     System.out.println(" 实例化Statement对象...");
     stmt = conn.createStatement();
    String sql;
     sql = "SELECT id, name, age,sex,Education,likes,text FROM peo";
    ResultSet rs = stmt.executeQuery(sql);
    out.println("<table border='1px' width='50%' align='center'>"
			+"<caption>信息统计一览表</caption>"
			+"<thead>"
					+"<tr>"
							+"	<th width='10%'>序号</th>"
							+"	<th width='10%'>姓名</th>"
							+"	<th width='10%'>年龄</th>"
							+"	<th width='10%'>性别</th>"
							+"	<th width='10%'>学历</th>"
							+"	<th width='30%'>爱好</th>"
							+"	<th width='20%'>操作</th>"
					+"</tr>"
					+"	</thead>"
					+"	<tbody>");
     // 展开结果集数据库
     while(rs.next()){
        // 通过字段检索
         int id  = rs.getInt("id");
       	 String name = rs.getString("name");
         String age = rs.getString("age");
         String sex = rs.getString("sex");
         String Education = rs.getString("Education");
         String likes = rs.getString("likes");
         String text = rs.getString("text");		
         // 输出数据
    			out.print("<tr>"
    					+"<td>"+id+"</td>"
    					+"<td>"+name+"</td>"
    					+"<td>"+age+"</td>"
    					+"<td>"+sex+"</td>"
    					+"<td>"+Education+"</td>"
    					+"<td>"+likes+"</td>"
    					+"<td><a href='peoinfo.jsp?choise=query&name="+'"'+name+'"'+"'title=''>操作</a><a href='peoinfo.jsp?choise=update&id="+'"'+id+'"'+"'title=''>修改</a><a href='peoinfo.jsp?choise=delete&name="+'"'+name+'"'+"'title=''>删除</a></td>"
    					+"</tr>");
    }
     out.print("</tbody>"
				+"</table>");
    // 完成后关闭
     rs.close();
     stmt.close();
    conn.close();
 }catch(SQLException se){
     // 处理 JDBC 错误
     se.printStackTrace();
 }catch(Exception e){
     // 处理 Class.forName 错误
     e.printStackTrace();
 }finally{
     // 关闭资源
     try{
         if(stmt!=null) stmt.close();
     }catch(SQLException se2){
     }// 什么都不做
     try{
         if(conn!=null) conn.close();
     }catch(SQLException se){
         se.printStackTrace();
     }
 }	
%>
</body>
</html>